<template>
	<view class="detail_container">
		<view class="status_container">
			<view class="status_title">
				<view v-if="dataValue.status == 1">待支付</view>
				<view v-if="dataValue.status == 2">待接单</view>
				<view v-if="dataValue.status == 6">待服务</view>
				<view v-if="dataValue.status == 7">服务中</view>
				<!-- <view v-if="dataValue.status == 3">已完成</view> -->
				<view v-if="dataValue.status == 5">已取消</view>
				<view v-if="dataValue.status == 4">已退款</view>
				<view v-if="dataValue.status == 9||dataValue.status == 10">已完成</view>
			</view>
			<view class="status_remind" v-if="dataValue.status == 1">
				<text>订单于</text>
				<u-count-down :time="timer" format="HH:mm:ss"></u-count-down>
				<text>分钟后自动取消，请及时支付</text>
			</view>
		</view>
		<view class="service_container">
			<view class="title">服务信息</view>
			<view class="list_item" style="margin-top: 40rpx;">
				<view>服务名称</view>
				<view>{{dataValue.service_name}}</view>
			</view>
			<view class="list_item">
				<view>选择医院</view>
				<view>{{dataValue.hospital_name}}</view>
			</view>
			<view class="list_item">
				<view>期望就诊时间</view>
				<view>{{time_zhaunhuan(dataValue.reserve_time)}}</view>
			</view>
			<view class="list_item">
				<view>就诊人</view>
				<view>{{dataValue.patient_name}}</view>
			</view>
			<view class="list_item">
				<view>就诊人联系电话</view>
				<view @click="telFun">{{dataValue.patient_mobile}}</view>
			</view>
			<view class="list_item" style="margin-top: 20rpx; padding-bottom: 40rpx;height: auto;">
				<view>服务需求</view>
				<view style="width: 300rpx;text-align: right;overflow-x: scroll;">{{dataValue.remark}}</view>
			</view>
		</view>
		<view class="order_container">
			<view class="title">订单信息</view>
			<view class="list_item" style="margin-top: 40rpx;">
				<view>订单号</view>
				<view>{{dataValue.order_code}}</view>
			</view>
			<view class="list_item">
				<view>联系人</view>
				<view>{{dataValue.patient_name}}</view>
			</view>
			<view class="list_item">
				<view>联系电话</view>
				<view>{{dataValue.patient_mobile}}</view>
			</view>
			<view class="list_item">
				<view>支付金额</view>
				<view>{{'￥'+dataValue.order_common_price}}</view>
			</view>
			<view class="list_item">
				<view>支付方式</view>
				<view>{{'在线支付'}}</view>
			</view>


			<view class="btn" v-if="dataValue.status == 7">
				<view @click="showGetconts=true">结束服务</view>
			</view>
		</view>
		<view class="footer_container" v-if="dataValue.status == 1">
			<view class="query_btn">
				<button open-type="contact" size="mini" style="padding: 0;margin:0;border-radius: 10rpx;">
					<view class="btn">联系客服</view>
				</button>
			</view>
			<view class="pay_btn">
				<view @click="goPay()">去付款</view>
			</view>
		</view>


		<!-- 退出登录弹出层 -->
		<u-popup :show="showGetconts" mode="center" round="40rpx">
			<view class="popupGetconts">
				<text class="popupGetconts_comment">确定要结束吗</text>
				<view class="popupGetconts_btn">
					<text @click="showGetconts=false">取消</text>
					<text @click="jieshudingdanApi()">确定</text>
				</view>
			</view>
		</u-popup>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataValue: {},
				limitTimes: 30 * 60,
				timer: '',
				showGetconts: false,
			}
		},
		onLoad(options) {
			this.dataValue = JSON.parse(options.item);
			console.log(this.dataValue, "=======")
			this.dataValue.reserve_time = this.dataValue.reserve_time * 1000;
			if (this.dataValue.status == 1) {
				this.countDown(this.dataValue.create_time, this.limitTimes)
			}
		},
		methods: {
			//拨打电话：
			telFun() {
				uni.makePhoneCall({
					phoneNumber: this.dataValue.patient_mobile, //电话号码
					success: function(e) {
						console.log(e, '999999999')
					},
					fail: function(e) {
						console.log(e);
					}
				})
			},
			// 结束订单  
			jieshudingdanApi() {
				this.get('/api/qunvxckt/jieshudingdan', {
					id: this.dataValue.order_code,
					user_id: uni.getStorageSync("user_id"),
				}).then((data) => {
					if (data.code == 1) {
						this.showGetconts = false
						uni.showToast({
							title: "结束成功",
							duration: 1500,
							icon: "none"
						})
						uni.navigateBack({
							delta: 1
						})
					}
				})
			},
			//30分钟内完成付款
			countDown(createtime, limitTimes) {
				let self = this;
				let timmer = setInterval(function() {
					let endTime = createtime + limitTimes; //结束时间
					let nowTime = new Date().getTime() / 1000; //现在时间
					let ts = parseInt(endTime - nowTime); //时间差
					if (ts >= 0) {
						self.timer = ts * 1000;
					} else {
						clearInterval(timmer);
						self.cancelOrder();
					}
				}, 1000);

			},
			// 超时取消订单
			cancelOrder() {
				let self = this;
				self.post('/api/Qunvxckt/quxiaodingdan', {
					user_id: uni.getStorageSync("user_id"),
					order_code: self.dataValue.order_code
				}).then((data) => {
					uni.showToast({
						title: "订单超时，请重新下单",
						duration: 1500,
						icon: "none"
					})
					uni.navigateBack({
						delta: 1
					})
				})
			},
			// 订单支付
			goPay() {
				let self = this
				self.post('/api/Qunvxckt/dingdanzhifu', {
					user_id: uni.getStorageSync("user_id"),
					order_code: self.dataValue.order_code
				}).then((res) => {
					// 调用只支付
					uni.requestPayment({
						privider: 'wxpay',
						timeStamp: res.timeStamp,
						nonceStr: res.nonceStr,
						package: res.package,
						signType: res.signType,
						paySign: res.paySign,
						success: function(payRes) {
							uni.removeStorageSync('./fillin')
							uni.showToast({
								icon: 'none',
								title: '支付成功'
							})
							uni.navigateBack({
								delta: 1
							})
							// 支付和成功重新调用订单列表
						},
						fail: function(err) {
							uni.showToast({
								icon: 'none',
								title: '支付失败'
							})
							uni.navigateBack({
								delta: 1
							})
						}
					})
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	// 弹窗
	.popupGetconts {
		width: 614rpx;
		padding: 80rpx 60rpx 80rpx 60rpx;
		box-sizing: border-box;

		.popupGetconts_comment {
			display: block;
			font-size: 32rpx;
			color: #787B86;
			text-align: center;
			margin-bottom: 60rpx;
		}

		.popupGetconts_btn {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-top: 40rpx;

			text:nth-of-type(1) {
				display: inline-block;
				width: 260rpx;
				height: 88rpx;
				line-height: 88rpx;
				border-radius: 44rpx 44rpx 44rpx 44rpx;
				border: 2rpx solid #D1D1D6;
				margin-right: 14rpx;
				font-size: 30rpx;
				color: #787B86;
				text-align: center;
			}

			text:nth-of-type(2) {
				display: inline-block;
				width: 260rpx;
				height: 88rpx;
				line-height: 88rpx;
				border-radius: 44rpx 44rpx 44rpx 44rpx;
				background: #FF4E4D;
				margin-right: 14rpx;
				font-size: 30rpx;
				color: #FFFFFF;
				text-align: center;
			}
		}
	}

	.btn {
		padding-top: 50rpx;
		display: flex;
		justify-content: flex-end;
		background-color: #fff;
		padding-bottom: 50rpx;
		padding-right: 20rpx;

		view {
			width: 200rpx;
			text-align: center;
			padding: 5rpx 0;
			border-radius: 50rpx;
			border: 1px solid #5F5AF7;
			background-color: #5F5AF7;
			color: #fff;
			font-size: 26rpx;
		}
	}

	.detail_container {
		width: 100%;
		height: 100%;
		font-family: Microsoft YaHei-Bold, Microsoft YaHei;
	}

	.status_container {
		width: 100%;
		height: 110rpx;
		margin-top: 40rpx;

		.status_title {
			width: 100%;
			height: 42rpx;
			margin-top: 28rpx;
			text-align: center;
			line-height: 42rpx;
			font-size: 32rpx;
			font-weight: bold;
			color: #000000;
		}

		.status_remind {
			width: 100%;
			height: 36rpx;
			margin-top: 20rpx;
			margin-left: 114rpx;
			line-height: 42rpx;
			font-size: 28rpx;
			color: #666666;
			display: flex;
			flex-wrap: nowrap;
		}
	}

	.service_container {
		width: 670rpx;
		height: auto;
		margin: 40rpx auto;
		background: #FFFFFF;
		box-shadow: 0rpx 0rpx 20rpx 2rpx rgba(0, 0, 0, 0.05);
		border-radius: 10rpx;
	}

	.order_container {
		width: 670rpx;
		height: 422rpx;
		margin: 0 auto;
		margin-bottom: 200rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 0rpx 20rpx 2rpx rgba(0, 0, 0, 0.05);
		border-radius: 10rpx;
	}

	.footer_container {
		width: 750rpx;
		height: 160rpx;
		background: #FFFFFF;
		position: fixed;
		bottom: 0;
		left: 0;
		display: flex;
		justify-content: space-between;

		.query_btn {
			width: 260rpx;
			height: 120rpx;
			margin: 20rpx 40rpx 0;

			.btn {
				width: 260rpx;
				height: 90rpx;
				background: #FFFFFF;
				border-radius: 10rpx;
				border: 2rpx solid #5F5AF7;
				font-size: 32rpx;
				text-align: center;
				font-weight: 400;
				color: #5F5AF7;
				line-height: 90rpx;
				text-align: center;
			}
		}

		.pay_btn {
			width: 400rpx;
			height: 120rpx;
			margin: 20rpx 40rpx 0 0;

			view {
				width: 370rpx;
				height: 90rpx;
				line-height: 90rpx;
				background: #5F5AF7;
				font-size: 32rpx;
				text-align: center;
				border-radius: 10rpx;
				color: #FFFFFF;
			}
		}
	}

	.title {
		width: 100%;
		height: 122rpx;
		padding-left: 40rpx;
		line-height: 122rpx;
		border-bottom: 1rpx solid #F4F4F4;
		font-size: 32rpx;
		font-weight: bold;
		color: #000000;
	}

	.list_item {
		height: 36rpx;
		margin: 0 40rpx 10rpx;
		display: flex;
		justify-content: space-between;
		font-size: 28rpx;
		color: #666666;
		line-height: 36rpx;
	}
</style>